﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RRHH.Models;
using RRHH.RRHH_Service;
using System.Web.Routing;

namespace RRHH.Controllers
{
    public class ContratoEFController : Controller
    {
        private RRHH.RRHH_Service.RRHHServiceClient serviceRRHH = new RRHH.RRHH_Service.RRHHServiceClient();
        public int codigo ;



         public ActionResult Index()
         {
             return View();
        }

        //
        // GET: /ContratoEF/

         public ActionResult ListadoContratos(string id, string id2)
        {
          
            codigo = int.Parse(id);
           
            Session["data"] = id;
            Session["dataII"] = id2;
          
            //string p = parametro;
            return View(serviceRRHH.ListarContrato(int.Parse(id)));
           // RedirectToAction("WithTarget", new { controller = "Customers", action = "Edit", id = iNewId, target = "Tab1" }); 
        }


         public ActionResult ListarVencidos()
         {
             try
             {
                 int vencidos = int.Parse((string)Session["ContratosVencer"]);

                 if (vencidos > 0)
                 {
                     Session["ContratosVencer"] = 0;
                     return View(serviceRRHH.GestContratosVencidos());
                 }
                 else
                 {
                     return View();
                 }
             }
             catch (Exception)
             {
                 return View();
             }
            
         }

        //
        // GET: /ContratoEF/Details/5

        public ActionResult Details(int id = 0)
        {
            //CONTRATO contrato = serviceRRHH.ObtenerContrato(id);
            //if (contrato == null)
            //{
            //    return HttpNotFound();
            //}
            //return View(contrato);

            return null;
        }

        //
        // GET: /ContratoEF/Create

        public ActionResult Create()
        {
            string data;
            string dataII;

            using (RRHH_Service.RRHHServiceClient wsRRHH = new RRHHServiceClient())
            {                              
                
                //------------------------------LIST VIEW DE CARGO-------------------------//
                List<BECargo> cargolist = new List<BECargo>();
                cargolist = wsRRHH.ListarCargo().ToList<BECargo>();
                ViewData["dsCargo"] = new SelectList(cargolist, "IDAUTO", "DESCRIPCION");

                //------------------------------LIST VIEW DE ESTADO CONTRATO---------------//
                List<BEEstadoContrato> estadoContratoTOlist = new List<BEEstadoContrato>();
                estadoContratoTOlist = wsRRHH.ListarEstadoContrato().ToList<BEEstadoContrato>();
                ViewData["dsEstadoContrato"] = new SelectList(estadoContratoTOlist, "IDESTADO", "DESCRIPCION");

                //------------------------------LIST VIEW DE TIPO CONTRATO----------------//
                List<BETipoContrato> tipoContratoTOlist = new List<BETipoContrato>();
                tipoContratoTOlist = wsRRHH.ListarTipoContrato().ToList<BETipoContrato>();
                ViewData["dsTipoContrato"] = new SelectList(tipoContratoTOlist, "IDTIPOCONTRATO", "DESCRIPCION");

                data = Session["data"] as string;
                dataII = Session["dataII"] as string;
                //String DatosCompletos = wsRRHH.Obtener_x_ID(int.Parse(data)).DATOSCOMPLETOS;

                //ViewBag.Datos = DatosCompletos;
                //ViewBag.CODEMPLEADO = dataII;  



                return View();
            }


        }

        //
        // POST: /ContratoEF/Create

        [HttpPost]
        public ActionResult Create(BEContrato contrato, string dsCargo, string dsEstadoContrato, string dsTipoContrato )
        {
            string data;
            string dataII;
            if (ModelState.IsValid)
            {
                using (RRHH_Service.RRHHServiceClient wsRRHH = new RRHHServiceClient())
                {
                    data = Session["data"] as string;
                    dataII = Session["dataII"] as string;

                    contrato.IDCARGO = int.Parse(dsCargo);
                    contrato.IDESTADO = int.Parse(dsEstadoContrato);
                    contrato.IDTIPOCONTRATO = dsTipoContrato;
                    contrato.CODIGOEMPLEADO = dataII;
                    contrato.IDPERSONAL = int.Parse(data);

                    wsRRHH.CrearContrato(contrato);
                   
                    return RedirectToAction("ListadoContratos", new { id = data, id2 = dataII });
                }

            }

            return View(contrato);
        }

        //
        // GET: /ContratoEF/Edit/5

        public ActionResult Edit(int id = 0)
        {
            //CONTRATO contrato = db.CONTRATO.Find(id);
            //if (contrato == null)
            //{
            //    return HttpNotFound();
            //}
            //return View(contrato);

            return null;
        }

        //
        // POST: /ContratoEF/Edit/5

        [HttpPost]
        public ActionResult Edit(BEContrato contrato)
        {
            //if (ModelState.IsValid)
            //{
            //    db.Entry(contrato).State = EntityState.Modified;
            //    db.SaveChanges();
            //    return RedirectToAction("ListadoContratos");
            //}
            //return View(contrato);

            return null;
        }

        //
        // GET: /ContratoEF/Delete/5

        public ActionResult Delete(int id = 0)
        {
            //CONTRATO contrato = db.CONTRATO.Find(id);
            //if (contrato == null)
            //{
            //    return HttpNotFound();
            //}
            //return View(contrato);

            return null;
        }

        //
        // POST: /ContratoEF/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            //CONTRATO contrato = db.CONTRATO.Find(id);
            //db.CONTRATO.Remove(contrato);
            //db.SaveChanges();
            //return RedirectToAction("ListadoContratos");

            return null;
        }


    }
}